#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int k;
	cin >> k;
	k--;
	string s;
	vector<char> arr{ '0','1','2','3','4','5','6','7','8','9' };
	reverse(arr.begin(), arr.end());
	for (int i = 1; i <= 5; i++)
	{
		int num = 1;
		for (int step = 0; step < (5 - i); step++)
		{
			num *= (10 - i - step);
		}
		int span = k / num;
		//cout << span << endl;
		k = k % num;
		int cunt = 0;
		char c = '0';
		for (int j = 0; j < 10; j++)
		{
			if (arr[j] != -1 && cunt++ == span)
			{
				c = arr[j];
				arr[j] = -1;
				break;
			}
		}
		s += c;
	}
	cout << s;

	return 0;
}